<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  String basePath = request.getContextPath();
  Object email = request.getSession().getAttribute("email");
%>
<html>
<head>
  <title>小伙伴</title>
  <jsp:include page="../common/common-css.jsp"></jsp:include>
  <jsp:include page="../common/common-js.jsp"></jsp:include>
  <style type="text/css">
    a {
      text-decoration: none
    }

    a:hover {
      text-decoration: none
    }

    a:link {
      text-decoration: none
    }

    a:visited {
      text-decoration: none
    }
  </style>
</head>
<body style="padding: 0px;margin: 0px;background-color: #eaeaea">
<jsp:include page="../../head.jsp"></jsp:include>
<div class="container-fluid" style="padding: 0px">
  <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="margin: 0px;padding: 0px">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"style="padding: 0px;margin: 0px">
      <table style="width: 100%;">
        <tr>
          <td>
            <div id="head" style="display: none">
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" align="center" style="background-color:#996699;margin: 0px;padding: 20px 0px ">
                <img src="" style="width: 120px;height: 120px" alt="壕" id="champion" class="img-responsive img-circle img-thumbnail">
                <p class="text-center"style="padding: 10px 0px;color: #ffffff">
                  <span class="championName"style="font-size: large;"></span>
                  <span>以总收益</span>
                  <span>￥</span>
                  <span class="championIncome" style="font-size: large;"></span>
                  <span>占据收益榜首</span>
                </p>
              </div>
            </div>
          </td>
        </tr>
      </table>
    </div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"style="background-color: #ffffff;">
      <div id="usersArea">
        <table style="width: 100%;background-color: #ffffff">
          <tr>
            <td align="center" style="color: #d3d3d3;padding: 100px 0px;"><i
              class="icon-spinner icon-spin text-default-color"></i>&nbsp;正在加载数据......
            </td>
          </tr>
        </table>
      </div>
      <div id="users"style="padding: 30px 0px;"></div>
      <table style="width: 100%;display: none;" id="loadMore">
        <tr>
          <td align="center" class="load" style="padding: 40px;color: #ffffff">加载更多</td>
        </tr>
      </table>
      <table style="width: 100%;display: none;" id="loadOver">
        <tr>
          <td align="center" class="load" style="padding: 40px 0px"></td>
        </tr>
      </table>
    </div>
  </div>
</div>
<jsp:include page="../../foot.jsp"></jsp:include>
</body>
<script language="JavaScript">
  var pageNo = 1;
  function setChampion(name, logo,income) {
    if (logo == null || logo == '' || logo == undefined) {
      $("#champion").attr("src", "<%=basePath%>/img/user.png");
    } else {
      $("#champion").attr("src", logo + "-120x120");
    }
    $(".championName").text(name);
    $(".championIncome").text(income);
  }
  function loadUser(pageNo, pageSize) {
    var url = "<%=basePath%>/user/list";
    var param = {pageNo: pageNo, pageSize: pageSize};
    $.post(url, param, function (data, status) {
      var users = data.paginator.items;
      var user = data.shCompany;
      $("#usersArea").hide();
      var item;
      var subItem;
      var logo;
      var alias;
      if (users != null && users.length > 0) {
        if (pageNo == 1) {
          $("#head").show();
          // - 设置最佳硬汉封面
          setChampion(users[0].name, users[0].logo, users[0].inCount);
        }
        for (var i = 0; i < users.length; i++) {
          logo = "<%=basePath%>/img/user.png"
          if (users[i].logo != null && users[i].logo != '' && users[i].logo != undefined) {
            logo = users[i].logo + "-120x120";
          }
          alias = users[i].name;
          if (users[i].name == '' || users[i].name == null) {
            alias = users[i].email;
          }
          subItem = "";
          item = "";
          item += '<a href="<%=basePath%>/user/queryinfo?email=' + users[i].email + '">';
          item += '<div class="col-xs-4 col-sm-3 col-md-2 col-lg-1">';
          item += '<table style="width: 100%;">';
          item += '<tr>';
          item += '<td align="center"style="padding: 5px"><img style="width: 40px;height: 40px" class="img-responsive img-circle" src="' + logo + '"></td>';
          item += '</tr>';
          item += '<tr>';
          item += '<td align="center" style="padding: 5px;"><small>' + alias + '</small></td>';
          item += '</tr>';
          item += '</table>';
          item += '</div>';
          item += '</a>';
          sort++;
          $("#users").append(item);
        }
        if (users.length == pageSize) {
          // - 还有更多数据
          $("#loadOver").hide();
          $("#loadMore").show();
        } else {
          // - 没有更多数据
          $("#loadMore").hide();
          $("#loadOver").show();
        }
      } else {
        if (pageNo == 1) {
          // - 没有数据
          var noDataShow = '';
          noDataShow += '<div style="padding: 100px 0px;background-color: #f5f5f5" class="text-center">';
          noDataShow += '<h3 style="color: #cccccc">All user will be Here</h3>';
          noDataShow += '</div>';
          $("#users").empty();
          $("#users").append(noDataShow);
        }
      }
    })
  }
  var sort = 1;
  $(document).ready(function () {
    initStyle();
    loadUser(pageNo++, 100);
    $("#loadMore").click(function () {
      loadUser(pageNo++, 100);
    })
  })
</script>
</html>
